package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.WxProject;
import com.ruoyi.wechat.service.IWxProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>ClassName : WxProjectController</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2024/7/31 16:07
 */
@Api(value = "微信小程序API-营地其他项目管理", tags = {"微信小程序API-营地其他项目管理"})
@RestController
@RequestMapping("/wechat/project")
public class WxProjectController extends BaseController {

    @Autowired
    private IWxProjectService wxProjectService;

    @ApiOperation(value = "根据其他项目Id获取该营地下的其他项目列表", response = WxProject.class)
    @GetMapping("/getInfoByCampId/{campId}")
    public AjaxResult getInfoByCampId(@PathVariable("campId") String campId) {
        if (campId == null) {
            return error("营地Id不能为空");
        }
        List<WxProject> list = wxProjectService.getInfoByCampId(campId);
        return success(list);
    }

    @ApiOperation(value = "根据其他项目Id查询详细信息", response = WxProject.class)
    @GetMapping("/getInfoByProjectId/{projectId}")
    public AjaxResult getInfoByScenicId(@PathVariable("projectId") String projectId) {
        if (projectId == null) {
            return error("其他项目Id不能为空");
        }
        WxProject wxProject = wxProjectService.getInfo(projectId);
        return success(wxProject);
    }

    @ApiOperation(value = "添加其他项目并提交审批")
    @Log(title = "微信小程序API-营地其他项目管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WxProject wxProject){
        if (wxProject == null) {
            return error("数据不能为空");
        }
        if (wxProject.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxProject.getProjectName() == null) {
            return error("其他项目名称不能为空");
        }
        if (wxProject.getOriginalPrice() == null) {
            return error("原价不能为空");
        }
        return toAjax(wxProjectService.insertWxProject(wxProject));
    }

    @ApiOperation(value = "修改其他项目并提交审批")
    @Log(title = "微信小程序API-营地其他项目管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody WxProject wxProject) {
        if (wxProject == null) {
            return error("数据不能为空");
        }
        if (wxProject.getProjectId() == null) {
            return error("营地其他项目Id不能为空");
        }
        if (wxProject.getCampId() == null) {
            return error("营地Id不能为空");
        }
        if (wxProject.getProjectName() == null) {
            return error("其他项目名称不能为空");
        }
        if (wxProject.getOriginalPrice() == null) {
            return error("原价不能为空");
        }
        return toAjax(wxProjectService.updateWxProject(wxProject));
    }

    @ApiOperation(value = "根据其他项目Id完成删除")
    @Log(title = "微信小程序API-营地其他项目管理", businessType = BusinessType.DELETE)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "projectId", value = "其他项目Id", required = true, dataType = "String", paramType = "query"),
//    })
    @DeleteMapping("/delete/{projectId}")
    public AjaxResult delete(@PathVariable("projectId") String projectId){
        if (projectId == null) {
            return error("其他项目Id不能为空");
        }
        return toAjax(wxProjectService.deleteWxProjectByProjectId(projectId));
    }
}
